#if UNITY_EDITOR

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using UnityEditor;
using UnityEngine;

namespace utils.Attribute
{
    /// <summary>
    /// 增加对数组的处理
    /// </summary>
    public static class SerializedPropertyExtensions
    {
        public static string[] GetArray(this SerializedProperty arrayProperty)
        {
            return Enumerable.Range(0, arrayProperty.arraySize).Select(x => arrayProperty.GetArrayElementAtIndex(x).stringValue).ToArray();
        }


        private static void SetArraySize<T>(SerializedProperty arrayProperty, T[] values)
        {
            if (arrayProperty == null)
                throw new ArgumentNullException(nameof(arrayProperty));
            if (values == null)
                throw new ArgumentNullException(nameof(values));

            arrayProperty.arraySize = values.Length;
        }
        public static void SetArray(this SerializedProperty arrayProperty, GameObject[] values)
        {
            SetArraySize(arrayProperty, values);

            for (int i = 0; i < values.Length; i++)
            {
                arrayProperty.GetArrayElementAtIndex(i).objectReferenceValue = values[i];
            }
        }
        public static void SetArray(this SerializedProperty arrayProperty, int[] values)
        {
            SetArraySize(arrayProperty, values);

            for (int i = 0; i < values.Length; i++)
            {
                arrayProperty.GetArrayElementAtIndex(i).intValue = values[i];
            }
        }
        public static void SetArray(this SerializedProperty arrayProperty, float[] values)
        {
            SetArraySize(arrayProperty, values);

            for (int i = 0; i < values.Length; i++)
            {
                arrayProperty.GetArrayElementAtIndex(i).floatValue = values[i];
            }
        }
        public static void SetArray(this SerializedProperty arrayProperty, double[] values)
        {
            SetArraySize(arrayProperty, values);

            for (int i = 0; i < values.Length; i++)
            {
                arrayProperty.GetArrayElementAtIndex(i).doubleValue = values[i];
            }
        }
        public static void SetArray(this SerializedProperty arrayProperty, string[] values)
        {
            SetArraySize(arrayProperty, values);

            for (int i = 0; i < values.Length; i++)
            {
                arrayProperty.GetArrayElementAtIndex(i).stringValue = values[i];
            }
        }
        public static void SetArray(this SerializedProperty arrayProperty, Color[] values)
        {
            SetArraySize(arrayProperty, values);

            for (int i = 0; i < values.Length; i++)
            {
                arrayProperty.GetArrayElementAtIndex(i).colorValue = values[i];
            }
        }
    }
}

#endif